{include file="header/index" /}
		<div class="container whitebg">
			<div class="topnav clearfix">
				<div class="title fl">
					<h3>新增工程人员</h3>
				</div>
			</div>
			<p class="add_title">基本信息</p>

			<form class="form-horizontal" id="form" enctype="multipart/form-data">

				<div class="form-group displaycenter upload_header">
					<label class="col-sm-2 control-label">头像</label>
					<div class="col-sm-10 displaycenter">
						<div class="uploadheader">
							<div class="btn btn-default pointer">选择头像</div>
							<input type="file" name="avatar_img" id="avatar_img" class="webuploader-element-invisible" multiple="multiple" onchange="uploadFile()" accept="image/jpg,image/jpeg,image/png">
						</div>
						<img id="img" src="{if condition='((isset($data)))'}{:Config('IMAGES_PATH')}{$data.avatar_img}{else /}__IMG__/head_default.gif{/if}" class="upload_IMG img-circle" />
					</div>
				</div>

				<div class="form-group">
					<label class="col-sm-2 control-label">所属运营中心</label>
					<div class="col-sm-4">
						<select id="operation" name="" class="form-control" onChange="move()">
							<option value="">请选择运营中心</option>
							{if condition="(empty($operation))"}
							{else /}
							{volist name="operation" id="op"}
							<option value="{$op.o_id}" {if condition='((isset($data)) AND ($op.o_id == $data.o_id))'}selected{else /}{/if}>{$op.company_name}</option>
							{/volist}
							{/if}
						</select>
					</div>
				</div>				
				<div class="form-group">
					<label class="col-sm-2 control-label">所属行政区域</label>
					<div class="col-sm-4">
						<select id="administrative" name="administrative_id" class="form-control">
							<option value="">请选择行政区域</option>
							{if condition="(empty($administrative))"}
							{else /}
							{volist name="administrative" id="ad"}
							<option value="{$ad.a_id}" {if condition='((isset($data)) AND ($ad.a_id == $data.a_id))'}selected{else /}{/if}>{$ad.company_name}</option>
							{/volist}
							{/if}
						</select>
					</div>
				</div>	
				<div class="form-group">
					<label class="col-sm-2 control-label">工程人员名称</label>
					<div class="col-sm-4">
						<input type="text" class="form-control" name="engineers_name" id="engineers_name" value="{if condition='(empty($data))'}{else /}{$data.engineers_name}{/if}">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">工程人员电话</label>
					<div class="col-sm-4">
						<input type="text" maxlength="11" minlength="11" class="form-control" name="engineers_phone" id="engineers_phone" value="{if condition='(empty($data))'}{else /}{$data.engineers_phone}{/if}">
					</div>
					<span class="col-sm-2 control-label redcolor" style="text-align: left;">(作为登录账号)</span>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">登陆密码</label>
					<div class="col-sm-4">
						<input type="text" id="engineers_password" name="engineers_password" class="form-control" placeholder="输入登录密码{if condition='(empty($data.a_id))'}(不填默认123456){else /}(如不修改可不填){/if}">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">工程人员编号</label>
					<div class="col-sm-4">
						<input type="text" readonly="readonly" class="form-control" name="engineers_number" id="engineers_number" placeholder="自动生成六位数字" value="">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">身份证号码</label>
					<div class="col-sm-4">
						<input type="text" maxlength="18" minlength="15" class="form-control" name="engineers_idcard" id="engineers_idcard" value="{if condition='(empty($data))'}{else /}{$data.engineers_idcard}{/if}">
					</div>
				</div>

					<div class="form-group">
						<label class="control-label col-sm-2">省</label>
						<div class="col-sm-2">
							<select name="" id="province"  onChange="moveCity()" class="form-control">
								<option value="">选择省份</option>
								{volist name="Province" id="pr"}
								<option value="{$pr.id}" {if condition='((isset($data)) AND ($pr.id == $data.province_id))'}selected{else /}{/if}>{$pr.area_name}</option>
								{/volist}
							</select>
						</div>
						<label class="control-label col-sm-1" style="width: 25px">市</label>
						<div class="col-sm-2">
							<select name="" id="city"	onChange="moveArea()" class="form-control col-sm-2">
								<option value="">选择市</option>

								{volist name="City" id="ci"}
								{if condition='((isset($data)) AND ($ci.id == $data.city_id))'}
								<option value="{$ci.id}" {if condition='((isset($data)) AND ($ci.id == $data.city_id))'}selected{else /}{/if}>{$ci.area_name}</option>
								{/if}
								{/volist}
							</select>
						</div>
						<label class="control-label col-sm-1" style="width: 65px">区/县</label>
						<div class="col-sm-2">
							<select id="Area" onchange="moveAdress()" class="form-control administrative">
								<option value="">选择区/县</option>
								{volist name="Area" id="Ar"}
								{if condition='((isset($data)) AND ($Ar.id == $data.area_id))'}
								<option value="{$Ar.id}" {if condition='((isset($data)) AND ($Ar.id == $data.area_id))'}selected{else /}{/if}>{$Ar.area_name}</option>
								{/if}
								{/volist}
							</select>
						</div>
					</div>




				<div class="form-group">
					<label class="col-sm-2 control-label">家庭住址</label>
					<div class="col-sm-4">
						<input type="text" class="form-control" name="engineers_address" id="engineers_address" value="{if condition='(empty($data))'}{else /}{$data.engineers_address}{/if}">
					</div>
				</div>
				<div class="form-group" style="width: 65%; text-align: center;">
					<label class="radio-inline"><input type="radio" name="engineers_status" id="inlineRadio1" value="2" {if condition='((!empty($data)) AND ($data.engineers_status == 2))'}checked{else /}checked{/if}>正常</label>
					<label class="radio-inline"><input type="radio" name="engineers_status" id="inlineRadio2" value="1" {if condition='((!empty($data)) AND ($data.engineers_status == 1))'}checked{/if}>冻结</label>
					<input type="hidden" id="engineers_id" name="engineers_id" value="{if condition='(empty($data))'}{else /}{$data.engineers_id}{/if}">
				</div>
			</form>
			<form class="form-inline btnlists">
				<button type="button" id="but" class="btn btn-primary">添加保存</button>
				<button class="btn btn-default" onclick="backurl(this)">返回</button>
			</form>
		</div>
	</body>

</html>
<script type="text/javascript">
    /**
     * 图片显示
     */

    function uploadFile() {
        var file = document.getElementById("avatar_img").files[0];
        var reader = new FileReader();
        reader.onload = function(e) {
            img.src = this.result;
        };
        reader.readAsDataURL(file); //Base64
    }

	$("#but").click(function () {
	    console.log($("#province").val())
	    if ($("#province").val() == '' || $("#city").val() == '' ||$("#Area").val() == ''){
            layer.msg("请选择省市区", {icon: 2,time: 2000});
            return false;
		}
        var formData = new FormData($( "#form" )[0]);
        $.ajax({
            url:  "{:url('Operationmanagement/doEditPersonnel')}",  /*这是处理文件上传的servlet*/
            type: 'POST',
            data: formData,
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            dataType : 'json',
            success: function (returndata) {
                if(returndata.code == '1'){
                    layer.msg(returndata.msg, {icon: 1,time: 2000},function(){history.back();});
                }else{
                    layer.msg(returndata.msg, {icon: 2,time: 2000});
                }

            },error: function (returndata) {
                layer.msg('数据异常', {icon: 2,time: 2000});
                return false;
            }
        });

    });


    //工程人员：选择地址
    function move() {
        var operation = $("#operation").val();
        $.get("{:url('Operationmanagement/selectAdministrative')}",{operation:operation},function (data) {
            console.log(data)
            $("#administrative").empty();
            $("#administrative").append($("<option>").val("").text("请选择行政区域"));
            for (var i = 0;i<data.length;i++){
                var option = $("<option>").val(data[i].a_id).text(data[i].company_name);
                $("#administrative").append(option);
            }

        })
    }

	//返回上一页
	function backurl() {
		history.back();
	}

	//多行文本输入框剩余字数计算  
	function checkMaxInput(obj, maxLen) {
		if(obj == null || obj == undefined || obj == "") {
			return;
		}
		if(maxLen == null || maxLen == undefined || maxLen == "") {
			maxLen = 100;
		}

		var strResult;
		var $obj = $(obj);
		var newid = $obj.attr("id") + 'msg';

		if(obj.value.length > maxLen) { //如果输入的字数超过了限制  
			obj.value = obj.value.substring(0, maxLen); //就去掉多余的字  
			strResult = '<span id="' + newid + '" class=\'Max_msg\' ><br/>剩(' + (maxLen - obj.value.length) + ')字</span>'; //计算并显示剩余字数  
		} else {
			strResult = '<span id="' + newid + '" class=\'Max_msg\' ><br/>剩(' + (maxLen - obj.value.length) + ')字</span>'; //计算并显示剩余字数  
		}

		var $msg = $("#" + newid);
		if($msg.length == 0) {
			$obj.after(strResult);
		} else {
			$msg.html(strResult);
		}
	}

	//清空剩除字数提醒信息  
	function resetMaxmsg() {
		$("span.Max_msg").remove();
	}


    //选择地址
    function moveCity() {
        var province = $("#province").val();
        $.get("{:url('Operationmanagement/selectCity')}",{province:province},function (data) {
//            console.log(data);
            $("#city").empty();
            $("#city").append($("<option>").val("").text("请选择市"));
            for (var i = 0;i<data.length;i++){
                var option = $("<option>").val(data[i].id).text(data[i].area_name);
                $("#city").append(option);
            }
            $("#engineers_address").val($("#province option:selected").text());
        })
    }

    //选择地址
    function moveArea() {
        var city = $("#city").val();

        $.get("{:url('Operationmanagement/selectArea')}",{city:city},function (data) {
            $("#Area").empty();
            $("#Area").append($("<option>").val("").text("请选择区/县"));
            for (var i = 0;i<data.length;i++){
                var option = $("<option>").val(data[i].id).text(data[i].area_name);
                $("#Area").append(option);
            }
            $("#engineers_address").val($("#province option:selected").text()+$("#city option:selected").text());
        })
    }

    //拼接地址
	function moveAdress() {
        $("#engineers_address").val($("#province option:selected").text()+$("#city option:selected").text()+$("#Area option:selected").text());
    }
</script>